<template>
  <div class="eccount">
    <el-row :gutter="10">
      <el-col
        v-for="(item, index) in data"
        :key="index"
        :xs="24"
        :sm="12"
        :md="8"
        :lg="6"
      >
        <div
          class="eccount-card"
          :style="'background-image:' + 'url(' + item.bgImg + ')'"
        >
          <div class="body">
            <p>
              <span class="title">{{ item.name }}</span>
            </p>
            <p>
              <span class="num" v-if="decimals">{{ item.num }}</span>
              <animate-number
                from="0"
                :to="item.num"
                :key="item.num"
                class="num"
                v-else
              ></animate-number>
              <span v-if="item.unit" class="unit">{{ item.unit }}</span>
            </p>
          </div>
          <div class="head">
            <img :src="item.img" alt="" />
          </div>
        </div>
      </el-col>
    </el-row>
    <slot></slot>
  </div>
</template>
<script>
export default {
  props: {
    data: {
      type: Array,
      default: [],
    },
    // 是否为小数-小数animate-number不生效
    decimals: {
      require: false,
      type: Boolean,
      default: false,
    },
  },
};
</script>
<style scoped lang="scss">
.eccount {
  .el-row {
    .el-col {
      display: flex;
      align-items: center;
      justify-content: center;
      .eccount-card {
        width: 100%;
        height: 136px;
        // margin: 5px 0;
        border-radius: 6px;
        background-repeat: no-repeat;
        background-size: cover;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 20px;
        .head {
          width: 30%;
          height: 100%;
          text-align: right;
          padding-top: 20px;
          // display: flex;
          // align-items: center;
          // justify-content: center;
          // border-radius: 4px 0 0 4px;
          img {
            width: 36px;
            height: 36px;
          }
        }
        .body {
          width: 60%;
          height: 100%;
          display: flex;
          flex-direction: column;
          display: flex;
          justify-content: center;
          p {
            padding: 0;
            margin: 0;
            font-family: PingFangSC-Semibold, PingFang SC;
            color: #ffffff;
            .num {
              font-size: 36px;
              // font-weight: 600;
              line-height: 50px;
              margin-right: 10px;
            }
            .unit {
              font-size: 14px;
              font-weight: 300;
              line-height: 20px;
              margin-left: -4px;
            }
            .title {
              font-size: 16px;
              font-weight: bold;
              line-height: 20px;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
            }
          }
        }
      }
    }
  }
}
</style>
